<template>
	<view class="back">
		<view style="width: 100%;height: 5vh;text-align: center;margin-top: 3vh;"><span style="font-size: 20px;font-weight: bolder;">学员申请</span></view>
		<view style="width: 100vw;height: 85vh;background: #fff;margin-top: 30rpx;border-radius: 70rpx 70rpx 0rpx 0rpx;padding-bottom:5vh ;">
			<view style="width: 100%;height: 1vh;"></view>
			<view style="width: 90%;margin-left: 5%;height: 8vh;background-color:rgb(211, 211, 211);border-radius: 20rpx;margin-top: 1vh;" v-for="user in selectCoachInfoByCodeList" :key="user.id">
				<view style="width: 65%; float: left; margin-top: 2%;">
				<view style="font-weight: bolder;margin-left: 5%;margin-top: 1%;">学员姓名：<span style="font-weight: normal;">{{user.memberUserRealName}}</span></view>
				<view style="font-weight: bolder;margin-left: 5%;margin-top: 3%;">申请时间：<span style="font-weight: normal;">{{user.createTime}}</span></view>
				</view>
				<view style="width: 30%; float: right; margin-top: 3%;height: 3vh;margin-right: 2%;">
					<button  @click="haveCoach(user)" style="background-color:rgb(148, 171, 253);color: aliceblue;width: 70%;height: 130%;font-size: 12px;margin-top: 1vh;">通过申请</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				teacherinfo:{},
				selectCoachInfoByCodeList:[]
			}
		},
		created(){
			this.selectCoachInfoByCode()
		},
		methods: {
			// 通过申请按钮点击事件
			haveCoach(user){
				uni.request({
				    url: 'http://127.0.0.1:17000/memberUser/updateCoachCode',
				    method: "GET",
				    data: {
						memberUserId: user.memberUserId,
						coachCode: user.coachCode
					},
				    success: (res) => {
						console.log(res.data.data.data)
						if(res.data.data.data === 1){
							uni.showToast({
							  title: '同意申请成功',
							  icon: 'none',
							  duration: 1000,
							  backgroundColor: '#ff0000' // 设置为红色
							});
							// 延时执行selectCoachInfoByCode方法
						   setTimeout(() => {
						     this.selectCoachInfoByCode();
						   }, 1000); // 延时2秒后执行
							        
						}
					}
					})
				
			},
			// 查询申请数据
			selectCoachInfoByCode(){
				this.teacherinfo =uni.getStorageSync('teacherinfo')
				uni.request({
					url: "http://127.0.0.1:17000/CoachManagement/selectCoachInfoByCode",
					method: "GET",
					data: {
						coachCode:uni.getStorageSync('teacherinfo').coachCode
					},
					success: (res) => {
						console.log(res.data.data.data)
						this.selectCoachInfoByCodeList = res.data.data.data
					}
					})
			}
		}
	}
</script>

<style>
.content {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
}
.back {
	position: relative;
	width: 100%;
	height: 100vh;
	overflow: hidden; /* 超出部分隐藏，可根据需求调整 */
}
.back::before {
	content: "";
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background-color: #88e9f1; 
	z-index: -1;
}
</style>
